<template>
  <div class="search">
    <f-form ref="form" :action="api.drugsPlan" :form-key="this.formItem.drugsPlanId">
      <f-form-item label="供货商" type="select" name="supplierId" :showSearch="true"
                   :data="api.supplier.list" label-key="supplierName" value-key="supplierId"
                   :value="formItem.supplierId" @change="supplierChange" :required="true"/>
      <f-form-item label="药品" type="select" ref="drugs" name="drugsId" :showSearch="true" :data="api.drugs.list"
                   label-key="drugsName" value-key="drugsId" :value="formItem.drugsId"
                   :autoLoad="false" :required="true"/>
      <f-form-item label="采购数量" name="drugsNum" :value="formItem.drugsNum" :required="true"/>
      <f-form-item label="采购价" name="costPrice" :value="formItem.costPrice" :required="true"/>
      <f-form-item label="预付款" name="advancePayment" :value="formItem.advancePayment" :required="true"/>
      <f-form-item label="收款单位" name="receivingUnit" :value="formItem.receivingUnit"/>
      <f-form-item label="开户行" name="bank" :value="formItem.bank" :required="true"/>
      <f-form-item label="银行账号" name="bankNo" :value="formItem.bankNo" :required="true"/>
      <f-form-item label="采购日期" name="planDate" type="date" :value="formItem.planDate" :required="true"/>
    </f-form>
  </div>
</template>
<script>
  import api from './js/api'

  export default {
    name: 'bdpForm',
    props: {},
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, this.api),
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        formItem: this.getFormItem(),
        supplierParams: {}
      }
    },
    methods: {
      getFormItem() {
        return {
          drugsPlanId: '',
          supplierId: '',
          deptId: '',
          drugsId: '',
          companyId: '',
          drugsNum: '',
          costPrice: '',
          planAmount: '',
          advancePayment: '',
          returnAmount: '',
          planDate: '',
          checkState: '',
          receivingUnit:'',
          bank:'',
          bankNo:'',
          updateTime: '',
          createTime: ''
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        if (data && data.drugsPlanId) {
          let params = {
            drugsPlanId: data.drugsPlanId
          }
          this.refs['form'].getDetails(params, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({}, callback)
      },
      supplierChange(value) {
        this.supplierParams.supplierId = value
        this.$refs.drugs.initData(this.supplierParams)
        //清除选择的药品
        this.$refs.form.resetField('drugsId')
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
